package edu.bit.water.controller;

import edu.bit.water.entity.EntityClassifiedStandard;
import edu.bit.water.entity.EntityWaterCount;
import edu.bit.water.entity.MetaWaterCount;
import edu.bit.water.service.EntityWaterCountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/entity_water_count")
public class EntityWaterCountController {

    @Autowired
    private EntityWaterCountService entityWaterCountService;

    /**
     * 查询ENTITY_CLASSIFIED_INFO中的记录
     *
     * @return ENTITY_CLASSIFIED_INFO中的所有记录
     */
    @RequestMapping("/select")
    @ResponseBody
    public Map<String, Object> select(int last_id) {
        Map<String, Object> modelMap = new HashMap<>();
        List<EntityWaterCount> list = entityWaterCountService.select(last_id);
        modelMap.put("status", "success");
        modelMap.put("rows", list);
        return modelMap;
    }

    /**
     * 更新记录
     *
     * @param entityWaterCount 标签记录实体
     * @return 成功返回1, 失败返回0
     */

    @RequestMapping("/update")
    @ResponseBody
    public Map<String, String> update(EntityWaterCount entityWaterCount) {
        return entityWaterCountService.update(entityWaterCount);
    }

    /**
     * 更新记录
     *
     * @param entityClassifiedStandard 标签记录实体
     * @return 成功返回1, 失败返回0
     */

    @RequestMapping("/state_update")
    @ResponseBody
    public Map<String, String> stateUpdate(EntityClassifiedStandard entityClassifiedStandard) {
        return entityWaterCountService.stateUpdate(entityClassifiedStandard);
    }

    /**
     * 查询META_CLASSIFIED_STANDARD_INFO中的记录
     *
     * @return META_CLASSIFIED_STANDARD_INFO中的与standNum相应的所有记录
     */
    @RequestMapping("/get_meta_data")
    @ResponseBody
    public Map<String, Object> getMetaData(String entity_classified_standard_num) {
        Map<String, Object> modelMap = new HashMap<>();
        List<MetaWaterCount> list = entityWaterCountService.getMetaData(entity_classified_standard_num);
        modelMap.put("status", "success");
        modelMap.put("rows", list);
        return modelMap;
    }

    /**
     * @param entityWaterCount 标签记录实体
     * @return 成功返回1,失败返回0
     */
    @RequestMapping("/insert_water_count_data")
    @ResponseBody
    public Map<String, String> insertWaterCountData(EntityWaterCount entityWaterCount){
        return entityWaterCountService.insertWaterCountData(entityWaterCount);
    }

    /**
     * 删除记录
     * @param ids 删除记录的标识符
     * @return 成功返回1,失败返回0
     */
    @RequestMapping("/delete")
    @ResponseBody
    public Map<String, Object> delete(@RequestBody List<Integer> ids){
        Map<String, Object> modelMap = new HashMap<>();
        int n = entityWaterCountService.delete(ids);
        if(n == 1) {
            modelMap.put("status", "success");
        }
        else
            modelMap.put("status", "failed");
        return modelMap;
    }
}